package zdar.entities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

import zdar.processing.CharSheetDisplay;

/**
 * Contains the basic information of the different unit types.
 * Each unit object will be written based on Unit XML data.
 * This class just serves as a base template for different unit types.
 * The active units will have seperate objects
 * 
 * This is basically the character sheet.
 * @author danbye50
 *
 */

public class UnitTemplate {
	protected String type;
	protected String description;
	protected String displayName;
	protected boolean wildcard;
	
	protected int agility, smarts, spirit, strength, vigor;
	protected int pace, parry, toughness;
	protected HashMap<String, Integer> skills;
	//public ArrayList<Action2> meleeAttacks;
	//public ArrayList<Action2> rangeAttacks;
	protected ArrayList<Action2> actions;
	
	public CharSheetDisplay charSheetDisplay;
	//public enum Condition{ALIVE, BLEEDING_OUT, DEAD};
	
	protected int maxWounds, maxFatigue;
	
	
	// TODO eventually there can be a big ass constructor and then we can get rid of all the public getters and setters which no one but Unit should use
	public UnitTemplate(){
		skills = new HashMap<String, Integer>();
		//meleeAttacks = new ArrayList<Action2>();
		//rangeAttacks = new ArrayList<Action2>();
		actions = new ArrayList<Action2>();
	}
	
	
	public void printInfo(){
		System.out.println("========================");
		System.out.println(displayName);
		System.out.println(description);
		System.out.println("agility:	" + agility);
		System.out.println("smarts:		" + smarts);
		System.out.println("spirit:		" + spirit);
		System.out.println("strength:	" + strength);
		System.out.println("vigor:		" + vigor);
		System.out.println("Skills: (" + skills.size() + ")");
		for (Entry<String, Integer> entry : skills.entrySet()){
			System.out.println(entry.getKey() + ":	" + entry.getValue());
		}
	}
	

	
	
	
	public int getAttribute(String att){
		switch(att){
			case "agility": return agility;
			case "smarts": 	return smarts;
			case "spirit": 	return spirit;
			case "strength": return strength;
			case "vigor": 	return vigor;
		}
		if (skills.containsKey(att)){
			return skills.get(att);
		}
		return 4;
	}
	
	public int roll(String att){
		// TODO what about modifiers?
		switch(att){
			case "agility": return Dice.roll(agility);
			case "smarts": 	return Dice.roll(smarts);
			case "spirit": 	return Dice.roll(spirit);
			case "strength": return Dice.roll(strength);
			case "vigor": 	return Dice.roll(vigor);
		}
		if (skills.containsKey(att)){
			return Dice.roll(skills.get(att));
		}
		return (Dice.roll(4) - 2);
	}
	
	
	// TODO sort these out and move most of them to the constructor.
	// or at least into some Raise/Lower Attribute methods for public
	public int getAgility() {
		return agility;
	}


	public void setAgility(int agility) {
		this.agility = agility;
	}


	public int getSmarts() {
		return smarts;
	}


	public void setSmarts(int smarts) {
		this.smarts = smarts;
	}


	public int getSpirit() {
		return spirit;
	}


	public void setSpirit(int spirit) {
		this.spirit = spirit;
	}


	public int getStrength() {
		return strength;
	}


	public void setStrength(int strength) {
		this.strength = strength;
	}


	public int getVigor() {
		return vigor;
	}


	public void setVigor(int vigor) {
		this.vigor = vigor;
	}


	
	public int getPace() {
		return pace;
	}


	public void setPace(int pace) {
		this.pace = pace;
	}


	public int getParry() {
		return parry;
	}


	public void setParry(int parry) {
		this.parry = parry;
	}


	public int getToughness() {
		return toughness;
	}


	public void setToughness(int toughness) {
		this.toughness = toughness;
	}


	public String getType(){
		return type;
	}
	public void setType(String type){
		this.type = type;
	}	
	public String getDescription() {
		return description;
	}
	public String getDisplayName() {
		return displayName;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}
	public boolean isWildcard() {
		return wildcard;
	}
	public void setWildcard(boolean wildcard) {
		this.wildcard = wildcard;
	}
	public void setWildcard(String bool){
		if (bool.equalsIgnoreCase("1")){
			setWildcard(true);
		} else {
			setWildcard(false);
		}
		setMaxWounds();
		setMaxFatigue();
	}


	public int getMaxWounds() {
		return maxWounds;
	}
	public void setMaxWounds(int maxWounds) {
		this.maxWounds = maxWounds;
	}
	public void setMaxWounds(){
		if (wildcard)
			maxWounds = 3;
		else
			maxWounds = 1;
	}
	public int getMaxFatigue() {
		return maxFatigue;
	}
	public void setMaxFatigue(int maxFatigue) {
		this.maxFatigue = maxFatigue;
	}
	public void setMaxFatigue(){
		if (wildcard)
			maxFatigue = 2;
		else
			maxFatigue = 1;
	}
	
	//These return 0 since UnitTemplates will never be able to take damage.
	//This is so the charSheetdisplay will work for both pre-game and fight screens. And because I'm too lazy to have two of them.
	public int getWounds(){
		return 0;
	}
	public int getFatigue(){
		return 0;
	}
	
	public void setSkills(HashMap<String, Integer> skills){
		this.skills = skills;
	}
	public HashMap<String, Integer> getSkills(){
		return skills;
	}
	public void addSkill(String name, Integer value){	//ohh shit though don't we want dice here? arg that will be later
		skills.put(name, value);
	}
	public void setActions(ArrayList<Action2> actions){
		this.actions = actions;
	}
	public ArrayList<Action2> getActions(){
		return actions;
	}
	public void addAction(Action2 action){
		actions.add(action);
	}



}
